<template>
  <div class="app-container news-container">
    <el-form  size="mini":inline="true" :model="searchForm" @keyup.enter.native="getDataList()">
      <el-form-item label="查询：">
        <el-input clearable placeholder="输入信息标题" style="width: 300px;" v-model="searchForm.name"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="sts">
        <el-select placeholder="全部" style="width: 120px;" v-model="searchForm.label">
          <el-option
            :key="item.value"
            :label="item.label"
            :value="item.value"
            v-for="item in sts_lis">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="getDataList()" icon="el-icon-search" type="primary">查询</el-button>
        <el-button size="mini" @click="refDataList()" icon="el-icon-refresh" type="primary">重置</el-button>
        <el-button size="mini" @click="addOrUpdateHandle()" type="primary" v-if="Jurisdictionlist.indexOf('Add')>-1">添加通知</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" size="mini" :height="tableHeight" border
              ref="table" style="width: 100%;" v-loading="dataListLoading">
      <el-table-column align="center" header-align="center" label="序号" prop="typeName" width="80">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="信息标题" prop="title"></el-table-column>
      <el-table-column align="center" header-align="center" label="发布状态" prop="label">
        <template slot-scope="scope">
          {{ scope.row.label === 1 ? '草稿' : '已发布' }}
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="发布人" prop="created_user"></el-table-column>
      <el-table-column align="center" header-align="center" label="发布时间" prop="created_time"></el-table-column>
      <el-table-column align="center" header-align="center" label="阅读数" prop="readNum"></el-table-column>
      </el-table-column>
      <el-table-column align="center" fixed="right" header-align="center" label="操作" width="320">
        <template slot-scope="scope">
          <el-button size="mini" @click="lookHandelBtn(scope.row)" plain size="small" type="primary">详情</el-button>
          <el-button size="mini" @click="lookLogHandelBtn(scope.row)" plain size="small" type="success" v-if="scope.row.label==2 && Jurisdictionlist.indexOf('SendLog')>-1">发布记录</el-button>
          <el-button size="mini" @click="addOrUpdateHandle(scope.row)" plain size="small" type="primary" v-if="Jurisdictionlist.indexOf('Edit')>-1">编辑</el-button>
          <el-button size="mini" @click="handleDel(scope.row)" plain size="small" type="danger" v-if="Jurisdictionlist.indexOf('Delete')>-1">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination small
      :current-page="pageIndex"
      :page-size="pageSize"
      :page-sizes="[10, 20, 50, 100]"
      :total="totalPage"
      @current-change="currentChangeHandle"
      @size-change="sizeChangeHandle"
      layout="total, sizes, prev, pager, next, jumper"
      style="margin-top: 10px"
    ></el-pagination>

    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update @refreshList="getDataList" ref="addOrUpdate"></add-or-update>


    <!-- 发送记录弹框 -->
    <el-dialog :visible.sync="dialogSendLog" title="发送记录">
          <el-table
            :data="sendQyArr"
            style="width: 100%">
            <el-table-column prop="mainBodyId__name" label="主体"  width="180"></el-table-column>
            <el-table-column prop="areaId__name" label="区域"  width="180"></el-table-column>
            <el-table-column prop="qyId__name" label="企业名称"></el-table-column>
            <el-table-column prop="send_time" label="发送时间"></el-table-column>
          </el-table>
      <el-pagination small
        :current-page="pageIndex_"
        :page-size="pageSize_"
        :page-sizes="[10, 20, 50, 100]"
        :total="totalPage_"
        @current-change="currentChangeHandleBtn"
        @size-change="sizeChangeHandleBtn"
        layout="total, sizes, prev, pager, next, jumper"
        style="margin-top: 10px"
      ></el-pagination>
    </el-dialog>

    <!-- 信息详情弹框 -->
    <el-dialog :visible.sync="dialogSendInfo" title="通知详情">
      <div >
        <div class="info_title">{{current.title}}</div>
        <div class="info_time">{{current.created_time}}</div>
        <div class="info_content" v-html="current.content" ></div>
      </div>
    </el-dialog>




  </div>
</template>

<script>
  import AddOrUpdate from './add-or-update'
  import {mapGetters} from 'vuex'
  import {DeleteNoticeApi, GetSendLogApi, ListNoticeApi} from "../../../api/notice";

  export default {
    name: 'SerClassManage',
    computed: {
      ...mapGetters([
        'name'
      ])
    },
    data() {
      return {
        dialogSendLog: false,
        sendQyArr:[],
        pageIndex_: 1,
        pageSize_: 10,
        totalPage_: 0,

        dialogSendInfo: false,
        current:{},

        Jurisdictionlist: [], // 权限列表
        newcontent: '', // 公告内容
        searchForm: {
          label: '',
          name: '',
        },
        dialogTableVisible: false,
        dataList: [],
        tableHeight: 50,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,

        dataListLoading: false,
        dataListSelections: [],
        areaIdArr: [],
        mainBodyArr: [],
        addOrUpdateVisible: false,
        sts_lis: [
          {value: '1', label: '草稿'},
          {value: '2', label: '已发布'},
        ]
      }
    },
    components: {AddOrUpdate},
    mounted() {
      this.getDataList();
      // this.getMainBodiesFun();
      // this.getAreaArrFun();
      this.Jurisdictionlist = JSON.parse(localStorage.getItem('jurisdiction'))[this.$route.path];
      this.$nextTick(function () {
        this.tableHeight = window.innerHeight - 165 - 65;
        // 监听窗口大小变化
        let self = this;
        window.onresize = function () {
          self.tableHeight = window.innerHeight - 165 - 65;
        }
      });
    },
    methods: {
      lookLogHandelBtn(row){
        this.dialogSendLog = true;
        // 查看发送记录
        this.pageIndex_ = 1;
        this.pageSize_ = 10;
        this.totalPage_ = 0;
        const p = {
          id: row.id,
          pageNumber: this.pageIndex_,
          pageSize: this.pageSize_,
        };
        GetSendLogApi(p).then(res=>{
          this.sendQyArr = res.result;
          this.totalPage_ = res.total;
        })
      },
      lookHandelBtn(row){
        // 查看详情
        this.dialogSendInfo = true;
        console.log(row);
        this.current = row;
      },
      reserveHandelBtn(row){

      },
      //重置
      refDataList() {
        this.searchForm = {
          name: '',
          label: ''
        };
        this.getDataList()
      },
      showRowContent(row) {
        this.$nextTick(() => {
          this.dialogTableVisible = true;
          this.newcontent = row.content
          // this.$refs.quillEditIndex.open(row)
        })
      },
      //重置
      refInfo() {
        this.searchForm.name = '';
        this.getDataList()
      },
      handleDel(row) {
        this.$confirm('确认删除吗?', '提示', {
          type: 'warning'
        }).then(() => {
          let para = {
            ids: [row.id],
          };
          DeleteNoticeApi(para).then(res => {
            if (res.code == 200) {
              this.$message.success('删除成功');
              this.getDataList()
            }
          })
        }).catch(() => {

        })
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        const info = Object.assign(
          {pageNumber: this.pageIndex, pageSize: this.pageSize},this.searchForm,
        );
        ListNoticeApi(info)
          .then(res => {
            this.dataList = res.result.items;
            this.totalPage = res.result.total;
            this.dataListLoading = false
          })
          .catch(e => {
            this.dataList = [];
            this.totalPage = 0;
            this.dataListLoading = false
          })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList()
      },
      currentChangeHandleBtn(val) {
        this.pageIndex_ = val;
        this.getDataList()
      },
      sizeChangeHandleBtn(val) {
        this.pageSize_ = val;
        this.pageIndex_ = 1;
        this.getDataList()
      },



      // 多选
      selectionChangeHandle(val) {
      },
      // 新增 / 修改
      addOrUpdateHandle(row) {
        this.$refs.addOrUpdate.open(row, this.roleOptions)
      }
    },
  }
</script>
<style>
  .info_content img{
    max-width: 100%;
    height: auto;
  }
</style>
<style lang="scss" scoped>
  .info_title{
    font-size: 26px;
    font-weight: bolder;
    margin-bottom: 10px;
  }

  .fl {
    float: left;
  }

  .fr {
    float: right;
  }

  .clearfix::after {
    content: "";
    display: block;
    clear: both;
  }

  .thiscontainer {

  }

</style>
